class index_bgUI extends egret.Sprite {

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }
    private createView() {
        //添加背景
        var bg = drawReactShape(null, 0, 0, 640, 1136, 0x16c5ee);
        this.addChild(bg);

        var bg_shuiwen = createBitmap("bg_shuiwen_png", -560, 0);
        this.addChild(bg_shuiwen);
        var bg_shuiwen2 = createBitmap("bg_shuiwen_png", -560, -1136);
        this.addChild(bg_shuiwen2);
        egret.Tween.get(bg_shuiwen, { loop: true }).to({ x: 0, y: 1136 }, 10000);
        egret.Tween.get(bg_shuiwen2, { loop: true }).to({ x: 0, y: 0 }, 10000);

        //添加音乐logo
        // var music_logo = createBitmap("music_logo_png", 600, 40);
        // this.$stage.addChildAt(music_logo, 100);
        var music_play = createBitmap("music_play_png", 600, 40);
        this.$stage.addChild(music_play);
        music_play.touchEnabled = true;
        music_play.scaleX = .5;
        music_play.scaleY = .5;
        var music_stop = createBitmap("music_stop_png", 600, 40);
        this.$stage.addChild(music_stop);
        music_stop.touchEnabled = true;
        music_stop.scaleX = .5;
        music_stop.scaleY = .5;
        music_stop.visible = false;
        //添加音乐
        var sound = new egret.Sound;
        var soundChannel;
        var totalLength = 0;
        var curTime = 0;
        sound.addEventListener(egret.Event.COMPLETE, function () {
            soundChannel = sound.play(curTime, 1);
            totalLength = sound.length;
        }, this);
        sound.load("resource/assets/let_it_go.mp3");
        //通过点击音乐logo播放/暂停音乐
        // music_logo.addEventListener(egret.TouchEvent.TOUCH_TAP, zanting, this)
        // function zanting() {
        //     if (soundChannel == null) {
        //         soundChannel = sound.play(curTime);
        //         egret.Tween.resumeTweens(music_logo);
        //     } else {
        //         curTime = soundChannel.position;
        //         soundChannel.stop();
        //         soundChannel = null;
        //         egret.Tween.pauseTweens(music_logo);
        //     }
        // } 
        //播放
        music_stop.addEventListener(egret.TouchEvent.TOUCH_TAP, zanting, this)
        function zanting() {
            if (soundChannel == null) {
                soundChannel = sound.play(curTime);
                music_play.visible = true;
                music_stop.visible = false;
            }
        }
        music_play.addEventListener(egret.TouchEvent.TOUCH_TAP, bofang, this)
        function bofang() {
            if (soundChannel != null) {
                curTime = soundChannel.position;
                soundChannel.stop();
                soundChannel = null;
                music_play.visible = false;
                music_stop.visible = true;
            }
        }
    }
}